﻿var ajaxNow;
function createComment(obj)
{
    obj.html("<!--" + obj.html() + "-->");
}
function removeComment(obj)
{
    obj.html(obj.html().substring(4, obj.html().length - 3));
}
function showModal(contentId, areDisable)
{
    $("html").css("overflow", "hidden");
    $("body").css("overflow", "hidden");
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    scrTop = $("body").scrollTop();
    if (scrTop == 0)
        scrTop = $("html").scrollTop();
    $("body").append(
        '<div class="modal-mask"></div>' +
        '<div class="modal-window">' +
            '<div class="closeButton">' + '</div>' +
            $("#"+contentId).html() +
        '</div>');

    if (areDisable)
        $(contentId).html("");
    $(".modal-mask").click(function () { closeModal(false); });
    $(".modal-window .closeButton").click(function () { closeModal(false); });
    $('.modal-mask').css("top", scrTop + "px");
    $('.modal-window').css("top", (parseInt($(window).height() / 2) + parseInt(scrTop)) + "px");
    $('.modal-window').css("margin-top", "-" + (parseInt($('.modal-window').height() / 2)) + "px");
    $('.modal-window').css("margin-left", "-" + (parseInt($('.modal-window').width() / 2)) + "px");
    $('.modal-mask').fadeTo(1000, 0.8);
    $(".modal-window").show("normal");
}
function showModalAjax(controller, action, data)
{
    console.log("1");
    $("html").css("overflow", "hidden");
    $("body").css("overflow", "hidden");
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    scrTop = $("body").scrollTop();
    if (scrTop == 0)
        scrTop = $("html").scrollTop();
    $("body").append(
        '<div class="modal-mask"></div>' +
        '<div class="modal-window">' +
            '<div class="closeButton"></div>' +
            '<div id="ajaxResult"><img src="wait.gif"></div>' +
        '</div>');
    $(".modal-mask").click(function () { closeModal(false); });
    $(".modal-window .closeButton").click(function () { closeModal(false); });
    $('.modal-mask').css("top", scrTop + "px");
    $('.modal-mask').fadeTo(1000, 0.8);
    $(".modal-window").show("normal");
    doAjaxHtml(controller, action, data, function()
    {
        $('.modal-window').css("top", (parseInt($(window).height() / 2) + parseInt(scrTop)) + "px");
        $('.modal-window').css("margin-top", "-" + (parseInt($('.modal-window').height() / 2)) + "px");
        $('.modal-window').css("margin-left", "-" + (parseInt($('.modal-window').width() / 2)) + "px");
    },"#ajaxResult");
}
function closeModal()
{
    $("html").css("overflow", "auto");
    $("body").css("overflow", "auto");
    $(".modal-mask").remove();
    $('.modal-window').remove();
};
function startAjaxWait()
{
    $("html").css("overflow", "hidden");
    $("body").css("overflow", "hidden");
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    scrTop = $("body").scrollTop();
    if (scrTop == 0)
        scrTop = $("html").scrollTop();
    $("body").append(
        '<div class="modal-mask"></div>' +
        '<div class="modal-window">' +
            '<img src="wait.gif">' +
        '</div>');
    $('.modal-mask').css("top", scrTop + "px");
    $('.modal-window').css("top", (parseInt($(window).height() / 2) + parseInt(scrTop)) + "px");
    $('.modal-window').css("margin-top", "-" + (parseInt($('.modal-window').height() / 2)) + "px");
    $('.modal-window').css("margin-left", "-" + (parseInt($('.modal-window').width() / 2)) + "px");
    $('.modal-mask').fadeTo(0, 0.8);
    $(".modal-window").show();
}
function throwError()
{
    location.href = "/Home/Error";
}
//function fuckJs(obj)
//{
//    obj.attr("data-valu", obj.val());
//}